package legumes.client.services.callbacks;

import legumes.client.services.LegumesServicesHelper;
import legumes.client.services.util.rpc.SequencableRPCCall;
import legumes.shared.domain.LoginException;

public class SetPasswordCallback extends SequencableRPCCall<Void> {

	private String password;
	private String newPassword;
	private LoginException loginException;

	public SetPasswordCallback(String password_, String newPassword_) {
		super();
		password = password_;
		newPassword = newPassword_;
	}

	public LoginException getLoginException() {
		return loginException;
	}

	@Override
	public void onFailure(Throwable caught_) {
		if (caught_ instanceof LoginException) {
			loginException = (LoginException) caught_;
		} else {
			super.onFailure(caught_);
		}
		callNext();
	}

	@Override
	protected void doCall() {
		LegumesServicesHelper.LEGUMES_SERVICES.changePassword(password,
				newPassword, this);
	}

}
